﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using HMS.BL;
using HMS.Common;
using HMS.DL;

namespace HMS.PL.Forms
{
    public partial class ConfigCallback : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (IsPostBack == false)
            {

                string strOpern = String.IsNullOrEmpty(Request.QueryString["operation"]) ? "" : Request.QueryString["operation"].ToString();
                if (strOpern == null || strOpern == "")
                {
                    strOpern = Request.Form["oper"] + Request.QueryString["table"];
                }

                ConfigData objConfigData = new ConfigData();

                if (String.IsNullOrEmpty(Request.QueryString["reconstruct"]) == false)
                {
                    return;
                }

                switch (strOpern)
                {

                    case "get_XMasterListColumns":
                        Response.Write(objConfigData.GetXMasterListColumns());
                        break;
                    case "get_XMasterList":
                        objConfigData.sidx = String.IsNullOrEmpty(Request.Params["sidx"]) ? "" : Convert.ToString(Request.Params["sidx"].ToString());
                        objConfigData.sord = String.IsNullOrEmpty(Request.Params["sord"]) ? "desc" : Convert.ToString(Request.Params["sord"].ToString());
                        objConfigData.rows = String.IsNullOrEmpty(Request.Params["rows"]) ? 10 : Convert.ToInt32(Request.Params["rows"].ToString());
                        objConfigData.page = String.IsNullOrEmpty(Request.Params["page"]) ? 1 : Convert.ToInt32(Request.Params["page"].ToString());
                        objConfigData._search = String.IsNullOrEmpty(Request.Params["_search"]) ? false : Convert.ToBoolean(Request.Params["_search"]);
                        objConfigData.query = String.IsNullOrEmpty(Request.Params["searchQuery"]) ? "" : Convert.ToString(Request.Params["searchQuery"]);
                        Response.Write(objConfigData.GetXMasterListdata());
                        break;
                    case "addXMasterList":
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.AddXMasterList());
                        break;
                    case "editXMasterList":
                        objConfigData.ListId = String.IsNullOrEmpty(Request.Form["id"]) ? 0 : Convert.ToInt32(Request.Form["id"].ToString());
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.EditXMasterList());
                        break;
                    case "delXMasterList":
                        objConfigData.ListId = String.IsNullOrEmpty(Request.Form["id"]) ? 0 : Convert.ToInt32(Request.Form["id"].ToString());
                        Response.Write(objConfigData.DelXMasterList());
                        //Response.Write("true");
                        break;
                    //X_MASTER_LIST_COLUMNS
                    case "get_XMasterListColColumns":
                        objConfigData.ListId = String.IsNullOrEmpty(Request.QueryString["list_id"]) ? 0 : Convert.ToInt32(Request.QueryString["list_id"].ToString());
                        Response.Write(objConfigData.GetXMasterListColColumnsdata());
                        break;
                    case "get_XMasterListCol":
                        objConfigData.ListId = String.IsNullOrEmpty(Request.QueryString["list_id"]) ? 0 : Convert.ToInt32(Request.QueryString["list_id"].ToString());
                        objConfigData.sidx = String.IsNullOrEmpty(Request.Params["sidx"]) ? "" : Convert.ToString(Request.Params["sidx"].ToString());
                        objConfigData.sord = String.IsNullOrEmpty(Request.Params["sord"]) ? "desc" : Convert.ToString(Request.Params["sord"].ToString());
                        objConfigData.rows = String.IsNullOrEmpty(Request.Params["rows"]) ? 10 : Convert.ToInt32(Request.Params["rows"].ToString());
                        objConfigData.page = String.IsNullOrEmpty(Request.Params["page"]) ? 1 : Convert.ToInt32(Request.Params["page"].ToString());
                        objConfigData._search = String.IsNullOrEmpty(Request.Params["_search"]) ? false : Convert.ToBoolean(Request.Params["_search"]);
                        objConfigData.query = String.IsNullOrEmpty(Request.Params["searchQuery"]) ? "" : Convert.ToString(Request.Params["searchQuery"]);
                        Response.Write(objConfigData.GetXMasterListColdata());
                        break;
                    case "addXMasterListCol":
                        objConfigData.ListId = String.IsNullOrEmpty(Request.QueryString["list_id"]) ? 0 : Convert.ToInt32(Request.QueryString["list_id"].ToString());
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.AddXMasterListCol());
                        break;
                    case "editXMasterListCol":
                        objConfigData.ListId = String.IsNullOrEmpty(Request.QueryString["list_id"]) ? 0 : Convert.ToInt32(Request.QueryString["list_id"].ToString());
                        objConfigData.ListColId = String.IsNullOrEmpty(Request.Form["id"]) ? 0 : Convert.ToInt32(Request.Form["id"].ToString());
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.EditXMasterListCol());
                        break;
                    case "delXMasterListCol":
                        objConfigData.ListId = String.IsNullOrEmpty(Request.QueryString["list_id"]) ? 0 : Convert.ToInt32(Request.QueryString["list_id"].ToString());
                        objConfigData.hidColList = String.IsNullOrEmpty(Request.QueryString["hidColList"]) ? "0" : Convert.ToString(Request.QueryString["hidColList"]);
                        objConfigData.ListColId = String.IsNullOrEmpty(Request.Form["id"]) ? 0 : Convert.ToInt32(Request.Form["id"].ToString());
                        Response.Write(objConfigData.DelXMasterListCol());
                        break;                  
                    case "CreateDimConfigTable": 
                        objConfigData.ListId = String.IsNullOrEmpty(Request.QueryString["list_id"]) ? 0 : Convert.ToInt32(Request.QueryString["list_id"].ToString());
                        Response.Write(objConfigData.CreateDimConfigTable());
                        break;                  
                    //bind_reEng
                    case "bind_reEng":
                        Response.Write(objConfigData.bind_reEng());
                        break;
                    case "ReverseEngConfigTable": // to do later
                        objConfigData.ListName = Convert.ToString(Request.QueryString["list_name"]);
                        objConfigData.TableName = Convert.ToString(Request.QueryString["table_name"]);
                        Response.Write(objConfigData.ReverseEngConfigTable());
                        break;
                    //case "get_griddata":
                    //    objConfigData.ListName = Convert.ToString(Request.QueryString["list_name"]);
                    //    objConfigData.TableName = Convert.ToString(Request.QueryString["table_name"]);
                    //    Response.Write(objConfigData.get_griddata());
                    //    break;

                    //user tab
                    //User Type
                    case "get_UserTypeCol":
                        Response.Write(objConfigData.get_UserTypeCol());
                        break;
                    case "get_UserTypeData":
                        objConfigData.sidx = String.IsNullOrEmpty(Request.Params["sidx"]) ? "" : Convert.ToString(Request.Params["sidx"].ToString());
                        objConfigData.sord = String.IsNullOrEmpty(Request.Params["sord"]) ? "desc" : Convert.ToString(Request.Params["sord"].ToString());
                        objConfigData.rows = String.IsNullOrEmpty(Request.Params["rows"]) ? 10 : Convert.ToInt32(Request.Params["rows"].ToString());
                        objConfigData.page = String.IsNullOrEmpty(Request.Params["page"]) ? 1 : Convert.ToInt32(Request.Params["page"].ToString());
                        objConfigData._search = String.IsNullOrEmpty(Request.Params["_search"]) ? false : Convert.ToBoolean(Request.Params["_search"]);
                        objConfigData.query = String.IsNullOrEmpty(Request.Params["searchQuery"]) ? "" : Convert.ToString(Request.Params["searchQuery"]);
                        Response.Write(objConfigData.get_UserTypeData());
                        break;
                    case "addUserType":
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.addUserType());
                        break;
                    case "editUserType":
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.editUserType());
                        break;
                    case "delUserType":
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.delUserType());
                        break;
                    //User 
                    case "get_UserDataCol":
                        objConfigData.UserTypeId = String.IsNullOrEmpty(Request.QueryString["type_id"]) ? 0 : Convert.ToInt32(Request.QueryString["type_id"].ToString());
                        Response.Write(objConfigData.get_UserDataCol());
                        break;
                    case "get_UserData":
                        objConfigData.UserTypeId = String.IsNullOrEmpty(Request.QueryString["type_id"]) ? 0 : Convert.ToInt32(Request.QueryString["type_id"].ToString());
                        objConfigData.sidx = String.IsNullOrEmpty(Request.Params["sidx"]) ? "" : Convert.ToString(Request.Params["sidx"].ToString());
                        objConfigData.sord = String.IsNullOrEmpty(Request.Params["sord"]) ? "desc" : Convert.ToString(Request.Params["sord"].ToString());
                        objConfigData.rows = String.IsNullOrEmpty(Request.Params["rows"]) ? 10 : Convert.ToInt32(Request.Params["rows"].ToString());
                        objConfigData.page = String.IsNullOrEmpty(Request.Params["page"]) ? 1 : Convert.ToInt32(Request.Params["page"].ToString());
                        objConfigData._search = String.IsNullOrEmpty(Request.Params["_search"]) ? false : Convert.ToBoolean(Request.Params["_search"]);
                        objConfigData.query = String.IsNullOrEmpty(Request.Params["searchQuery"]) ? "" : Convert.ToString(Request.Params["searchQuery"]);
                        Response.Write(objConfigData.get_UserData());
                        break;
                    case "addUser":
                        objConfigData.UserTypeId = String.IsNullOrEmpty(Request.QueryString["type_id"]) ? 0 : Convert.ToInt32(Request.QueryString["type_id"].ToString());
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.addUser());
                        break;
                    case "editUser":
                        objConfigData.UserTypeId = String.IsNullOrEmpty(Request.QueryString["type_id"]) ? 0 : Convert.ToInt32(Request.QueryString["type_id"].ToString());
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.editUser());
                        break;
                    case "delUser":
                        objConfigData.UserTypeId = String.IsNullOrEmpty(Request.QueryString["type_id"]) ? 0 : Convert.ToInt32(Request.QueryString["type_id"].ToString());
                        objConfigData.allkeys = Request.Form;
                        Response.Write(objConfigData.delUser());
                        break;
                    case "get_SourceData":
                        Response.Write(objConfigData.get_SourceData());
                        break;
                    default:
                        Response.Write(objConfigData.GetXMasterListdata());
                        break;
                }
            }
        }

    }

}